import dayjs, { Dayjs } from "dayjs";
import { defineStore } from "pinia";
import { ref } from "vue";

const now = dayjs();

export const useGreenWaveStore = defineStore("green-wave", () => {
    const currentRoad = ref<null | any>(null);
    const weekRange = ref<[Dayjs, Dayjs]>([
        now.clone().subtract(2, "w"),
        now.clone().subtract(1, "w"),
    ]);
    const dateType = ref<number>(1);

    function updateRoad(road: any | null) {
        currentRoad.value = road;
    }
    function updateWeekRange(
        range: [Dayjs, Dayjs] | [string, string],
        _: [string, string]
    ) {
        weekRange.value = range as [Dayjs, Dayjs];
        updateRoad(null);
    }
    function updateDateType(type: any) {
        dateType.value = type;
        updateRoad(null);
    }

    return {
        currentRoad,
        updateRoad,

        weekRange,
        updateWeekRange,

        dateType,
        updateDateType,
    };
});
